﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.BLL;
using LGCourt.Logic.NBL.DBEntities;
using lgweb.common;
using KMFrame.Permission.Util;
using KMFrame.Core;
using LGCourt.Logic.Common;

namespace lgweb.inside.intColumn
{
    public partial class list : NeedValidatePage
    {
        public string _deptCode = string.Empty;
        public string _DetpName = "";
        public string _ClassID = "0";
        public string _DeptID = "0";
        public string _picUrl = string.Empty;
        public string _cate = "0";
        private int _pageIndex = 1;
        private string _keyword = string.Empty;
        private string _start = string.Empty;
        private string _end = string.Empty;
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                _picUrl = System.Configuration.ConfigurationManager.AppSettings["InfoManage"];
                _picUrl = string.IsNullOrEmpty(_picUrl) ? "/lgmanage/Systems/upload/" : _picUrl;

                GetParam();
                GetInfo();
                GetList();
            }
        }

        private void GetParam()
        {
            this._ClassID = string.IsNullOrEmpty(Request.QueryString["classid"]) ? "0" : Request.QueryString["classid"];
            this._DeptID = string.IsNullOrEmpty(Request.QueryString["deptid"]) ? "0" : Request.QueryString["deptid"];
            this._pageIndex = string.IsNullOrEmpty(Request.QueryString["PageIndex"]) ? 1 : Convert.ToInt32(Request.QueryString["PageIndex"]);
            this._cate = string.IsNullOrEmpty(Request.QueryString["cate"]) ? "0" : Request.QueryString["cate"];
            this._deptCode = string.IsNullOrEmpty(Request.QueryString["Code"]) ? "ZZC" : Request.QueryString["Code"].ToString();
            this._keyword = string.IsNullOrEmpty(Request.QueryString["keyword"]) ? "" : Request.QueryString["keyword"];           
            this._start = string.IsNullOrEmpty(Request.QueryString["start"]) ? "" : Request.QueryString["start"];
            this._end = string.IsNullOrEmpty(Request.QueryString["end"]) ? "" : Request.QueryString["end"];
        }

        //获取部门信息
        private void GetInfo()
        {
            ColInfo colInfoBLL = new ColInfo();
            DeptClassCondition param = new DeptClassCondition();
            if (_DeptID == "0")
            {
                DepartmentHandler departmentHandler = new DepartmentHandler();
                Department department = departmentHandler.GetDepartmentInfo(_deptCode);
                if (department != null)
                {
                    _DetpName = department.Name;
                }
                //根据名称取部门ID
                param.Source = _DetpName;
            }
            else
            {
                param.ClassID = int.Parse(_DeptID);
            }
            param.Name = "部门";
            V_DICT_SOURCE deptInfo = colInfoBLL.GetDeptSourceInfo(param);
            if (deptInfo == null)
            {
                deptInfo = new V_DICT_SOURCE();
                deptInfo.ID = 1;
            }
            _DeptID = deptInfo.ID.ToString();
            _DetpName = deptInfo.Source;           
            this.spDeptLink.InnerHtml = deptInfo.Name;
            this.spDeptLink.HRef = "/inside/department/index.aspx?deptid=" + this._DeptID;

            V_DICT_SOURCE classInfo = new V_DICT_SOURCE();
            if (int.Parse(_ClassID)> 0)
            {
                param.Name = "监察室栏目";
                param.ClassID = int.Parse(_ClassID);
                classInfo = colInfoBLL.GetDeptSourceInfo(param);
            }           
            else
            {
                DeptClassCondition classParam = new DeptClassCondition();
                classParam.Name = "监察室栏目";
                List<V_DICT_SOURCE> classInfoList = colInfoBLL.GetDeptSourceList(classParam);
                int classid = int.Parse(_cate) - 1;
                if (classInfoList.Count >= classid && classid >= 1)
                {
                    classInfo = classInfoList[classid - 1];
                }
            }
            if (classInfo == null)
            {
                classInfo = new V_DICT_SOURCE();
            }
            _ClassID = classInfo.ID.GetValueOrDefault(0).ToString();
            this.spNewsName.InnerHtml = classInfo.Source;

            this.txtKeyword.Value = _keyword;
            this.txtStartDate.Value = _start;
            this.txtEndDate.Value = _end;          
        }
       
        private void GetList()
        {
            ColInfo colInfoBLL = new ColInfo();
            DeptCondition deptParam = new DeptCondition();
            deptParam.PageSize = 20;
            deptParam.PageIndex = this._pageIndex;
            deptParam.ClassID = int.Parse(_ClassID);
            deptParam.DeptID = int.Parse(_DeptID);
            if (!string.IsNullOrEmpty(this._start))
            {
                deptParam.BegingDate = DateTime.Parse(this._start);
            }
            if (!string.IsNullOrEmpty(this._end))
            {
                deptParam.EndDate = DateTime.Parse(this._end);
            }
            deptParam.keyword = this._keyword;
            PageResult result = colInfoBLL.GetDeptColInfoPage(deptParam);

            if (result != null && result.ResultList != null)
            {
                this.rptInfoList.DataSource = (List<LGFY_Platform_Bmxx>)result.ResultList;
                this.rptInfoList.DataBind();
                this.pager1.RecordCount = result.TotalCount;
                this.pager1.TotalPage = result.PageCount;
                this.pager1.PageIndex = this._pageIndex;
                this.pager1.PageSize = 20;
                this.pager1.LinkUrl = string.Format("/inside/department/list.aspx?PageIndex={0}&classid={1}&deptid={2}&cate={3}&Code={4}&keyword={5}&start={6}&end={7}", this._pageIndex, this._ClassID, this._DeptID, this._cate, this._deptCode, this._keyword, this._start, this._end);
            }
        }
    }
}